package com.baosan.school.service.ipml;

import com.baosan.school.mapper.ReportMapper;
import com.baosan.school.po.Report;
import com.baosan.school.po.Result;
import com.baosan.school.po.ResultEnum;
import com.baosan.school.service.ReportService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @program: school
 * @description:
 * @author: heping
 * @create: 2022-01-14 11:33
 */
@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    private ReportMapper reportMapper;

    @Override
    public PageInfo<Report> getReport(Report report) {
        PageHelper.startPage(report.getPageNum(),report.getPageSize());
        List<Report> list = reportMapper.getReport(report);
        PageInfo<Report> page = new PageInfo<>(list);
        return page;
    }


    @Override
    public Result<Report> getOne(Report report) {
        Result<Report> result = new Result<>();
        result.setCode(ResultEnum.SUCCESS.getKey());
        if(StringUtil.isEmpty(report.getStuNum())){
            result.setCode(ResultEnum.ERROR.getKey());
            result.setMsg("学号错误");
        }else{
            Report resultPO = reportMapper.getOne(report);
            result.setData(resultPO);
        }
        return result;
    }

    /**
     * @Description: 获取班级列表
     * @Author: ideal
     * @Date: 2022/1/14 15:36
     */
    @Override
    public Result<List<Report>> getClassList(Report report) {
        Result<List<Report>> result = new Result<>();
        result.setCode(ResultEnum.SUCCESS.getKey());
        if(StringUtil.isEmpty(report.getCls())){
            result.setCode(ResultEnum.ERROR.getKey());
            result.setMsg("请输入班级");
        }else{
            List<Report> reports = reportMapper.getClassList(report);
            result.setData(reports);
        }
        return result;
    }
}

